package com.shuoyue.adven.init;

import com.shuoyue.adven.entity.Settings;
import com.shuoyue.adven.network.RetrofitClient;
import com.sm.appbase.base.basemvp.BaseModel;
import com.sm.appbase.base.basemvp.BasePresenter;
import com.sm.appbase.base.basemvp.BaseView;
import com.sm.appbase.net.base.ApiSubscriber;
import com.sm.appbase.net.base.BaseResult;
import com.sm.appbase.net.base.Optional;

import io.reactivex.Observable;

public interface AppSettingContract {
    interface View extends BaseView {
        void getSettingSuc(Settings settings);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        void getSettings() {
            apply(model.getSetting())
                    .subscribe(new ApiSubscriber<Optional<Settings>>(mView, this) {
                        @Override
                        public void onNext(Optional<Settings> settingsOptional) {
                            super.onNext(settingsOptional);
                            mView.getSettingSuc(settingsOptional.getIncludeNull());
                        }
                    });
        }
    }

    class Model extends BaseModel {

        public Observable<BaseResult<Settings>> getSetting() {
            return RetrofitClient.getInstance().getApi().getSettings();
        }
    }
}
